package com.lechuang.member.controller;

import cn.hutool.json.JSONUtil;
import com.lechuang.common.request.PageRequest;
import com.lechuang.common.result.PageResult;
import com.lechuang.common.result.Result;
import com.lechuang.member.dto.*;
import com.lechuang.member.entity.Member;
import com.lechuang.member.manager.MemberManagementManager;
import com.lechuang.member.vo.MemberDictCommonVo;
import com.lechuang.member.vo.MemberListVo;
import com.lechuang.member.vo.MemberVo;
import com.lechuang.user.vo.UserVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/memberManage")
@Log4j2
@Tag(name = "会员管理类")
public class MemberManagementController {

    @Resource
    private MemberManagementManager memberManagementManager;



    @Operation(summary = "会员列表查询")
    @PostMapping("/queryList")
    public  Result<PageResult<MemberListVo>>  memberQueryList(@RequestBody PageRequest<MemberListDto> pageRequest){
        log.info("会员列表查询------{}", JSONUtil.toJsonStr(pageRequest));
        PageResult<MemberListVo>  pageResult = memberManagementManager.memberPage(pageRequest);
        return Result.success(pageResult);
    }

    @Operation(summary = "认证信息查询")
    @GetMapping("/authInfo")
    public  Result<MemberVo>  authInfo(@RequestParam Long id){
        log.info("会员认证信息查询------id{}", JSONUtil.toJsonStr(id));
        MemberVo memberVo =  memberManagementManager.authInfo(id);
        return Result.success(memberVo);
    }

    @Operation(summary = "会员认证")
    @PostMapping("/auth")
    public  Result  memberAuth(@RequestBody MemberAuthDto memberAuthDto){
        log.info("会员认证------memberAuthDto:{}", JSONUtil.toJsonStr(memberAuthDto));
         memberManagementManager.memberAuth(memberAuthDto);
        return Result.success();
    }

    @Operation(summary = "会员停用启用")
    @PostMapping("/active")
    public  Result  memberActive(@RequestBody MemberActiveDto memberActiveDto){
        log.info("会员启用停用------memberAuthDto:{}", JSONUtil.toJsonStr(memberActiveDto));
        memberManagementManager.memberActive(memberActiveDto);
        return Result.success();
    }

    @Operation(summary = "会员详情查询")
    @PostMapping("/queryById")
    public  Result<MemberListVo>  queryById(@RequestBody MemberRequestDto memberRequestDto){
        log.info("会员详情查询------memberRequestDto:{}", JSONUtil.toJsonStr(memberRequestDto));
        MemberListVo memberListVo = memberManagementManager.queryById(memberRequestDto);
        return Result.success(memberListVo);
    }

    @Operation(summary = "修改资料")
    @PostMapping("/updateById")
    public  Result  updateById(@RequestBody MemberRequestDto memberRequestDto){
        log.info("会员修改资料------memberRequestDto:{}", JSONUtil.toJsonStr(memberRequestDto));
        memberManagementManager.updateMemberInfo(memberRequestDto);
        return Result.success();
    }

    @Operation(summary = "修改奖励")
    @PostMapping("/updateBonus")
    public  Result  updateBonus(@RequestBody MemberBonusRequestDto memberBonusRequestDto){
        log.info("会员修改奖励------memberBonusRequestDto:{}", JSONUtil.toJsonStr(memberBonusRequestDto));
        memberManagementManager.updateBonus(memberBonusRequestDto);
        return Result.success();
    }

    @Operation(summary = "提现状态修改")
    @PostMapping("/updateWithdraw")
    public  Result  updateWithdraw(@RequestBody MemberRequestDto memberRequestDto){
        log.info("会员提现状态修改------memberRequestDto:{}", JSONUtil.toJsonStr(memberRequestDto));
        memberManagementManager.updateWithdraw(memberRequestDto);
        return Result.success();
    }


    @Operation(summary = "互转状态修改")
    @PostMapping("/updateTransfer")
    public  Result  updateTransfer(@RequestBody MemberRequestDto memberRequestDto){
        log.info("会员互转状态修改------memberRequestDto:{}", JSONUtil.toJsonStr(memberRequestDto));
        memberManagementManager.updateTransfer(memberRequestDto);
        return Result.success();
    }

    @Operation(summary = "修改新邀请人")
    @PostMapping("/updateInviter")
    public  Result  updateInviter(@RequestBody MemberRequestDto memberRequestDto){
        log.info("会员新邀请人修改------memberRequestDto:{}", JSONUtil.toJsonStr(memberRequestDto));
        memberManagementManager.updateInviter(memberRequestDto);
        return Result.success();
    }


    //feign调用
    @Operation(summary = "根据用户id查询会员信息")
    @PostMapping("/queryByUserId")
    public  Result<MemberVo>  queryByUserId(@RequestParam(required = true) Long  userId){
        log.info("根据用户id查询会员信息------userId:{}", userId);
        MemberVo memberVo = memberManagementManager.queryByUserId(userId);
        return Result.success(memberVo);
    }

    @Operation(summary = "查询字典默认值")
    @GetMapping("/queryDefaultDict")
    public  Result<MemberDictCommonVo>  queryDefaultDict(){
        log.info("查询字典默认值");
        MemberDictCommonVo memberDictCommonVo = memberManagementManager.queryDefaultDict();
        return Result.success(memberDictCommonVo);
    }

    @Operation(summary = "添加会员信息")
    @PostMapping("/saveMember")
    public  Result saveMember(@RequestBody SaveMemberDto saveMemberDto){
        log.info("添加会员信息------saveMemberDto:{}", JSONUtil.toJsonStr(saveMemberDto));
        memberManagementManager.saveMember(saveMemberDto);
        return Result.success();
    }

    @Operation(summary = "修改会员信息")
    @PostMapping("/updateMemberByUserId")
    public  Result updateMemberByUserId(@RequestBody SaveMemberDto saveMemberDto){
        log.info("修改会员信息------saveMemberDto:{}", JSONUtil.toJsonStr(saveMemberDto));
        memberManagementManager.updateMemberByUserId(saveMemberDto);
        return Result.success();
    }


}
